<template>
  <div class="app-container">
    <SearchContent :queryParams="queryParams" labelWidth="145px" @query="handleQuery" @reset="resetQuery">
      <el-col :span="6">
        <el-form-item label="车牌号/车架号:">
          <el-input v-model="queryParams.carNoVinNo" clearable placeholder="请输入车牌号/车架号"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="品牌/车系/车型:">
          <linkage-select @changeNode="linkageChange" v-model="linkageList" placeholder="请选择品牌/车系/车型"/>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车辆状态:">
          <el-select v-model="queryParams.businessType" placeholder="请选择车辆状态">
            <el-option :label="v.label" :value="v.value" v-for="v in dict.type.car_business_type" :key="v.value">
            </el-option>
          </el-select>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="维修签约厂:" prop="maintenanceShop">
          <el-input v-model="queryParams.maintenanceShop" clearable placeholder="请输入维修签约厂"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="客户名称:" prop="customerName">
          <el-input v-model="queryParams.customerName" clearable placeholder="请输入客户名称"></el-input>
        </el-form-item>
      </el-col>
      <el-col :span="6">
        <el-form-item label="车辆大区:">
          <city-select v-model="citySelection" placeholder="请选择车辆大区" ref="citySelect" :showAllLevels="false"
                       @change="citySelectionChange"></city-select>
        </el-form-item>
      </el-col>
      <!--      <el-col :span="6">-->
      <!--        <el-form-item label="维保状态:">-->
      <!--           <el-select placeholder="请选择维保状态"> </el-select> -->
      <!--        </el-form-item>-->
      <!--      </el-col>-->
    </SearchContent>
    <div class="card-wrap card-padding">
      <div class="table-title-wrap justify-end">
        <e-button type="primary" size="mini" v-hasPermi="['ghlt:ghltList:derive']"
                  @click="handleExport">导出
        </e-button>
      </div>
      <table-page :loading="loading" :dataList="dataList" :total="total" :page.sync="queryParams.pageNum"
                  :limit.sync="queryParams.pageSize" @setSizeCurrent="getList" border>
        <template slot="tableColAc">
          <el-table-column label="操作" align="center" fixed="left" width="100">
            <template slot-scope="{ row }">
              <el-button size="mini" type="text" @click="viewOpen(row)" v-hasPermi="['ghlt:ghltList:view']">查看
              </el-button>

              <el-button size="mini" type="text" v-hasPermi="['ghlt:ghltList:dele']" @click="del(row)">删除</el-button>
            </template>
          </el-table-column>
        </template>

        <template slot="tableCol">
          <el-table-column align="center" label="车牌号" min-width="100" prop="carNo">
          </el-table-column>
          <el-table-column align="center" label="车架号" min-width="180" show-overflow-tooltip prop="vinNo"/>
          <el-table-column align="center" label="品牌/车系/车型" show-overflow-tooltip width="320">
            <template slot-scope="{ row }">
              {{ row.brandName }}{{
                row.seriesName ? "/" + row.seriesName : ""
              }}{{ row.modelName ? "/" + row.modelName : "" }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="车辆大区"  width="160">
            <template #default="{row}">
              <span v-if="row.region">{{ row.region }} </span>

            </template>
          </el-table-column>
          <el-table-column align="center" label="公里数" width="120" prop="travelMeligile"/>
          <el-table-column align="center" label="维修签约厂" width="120" prop="maintenanceShop"/>
          <el-table-column align="center" label="车辆状态" width="160">
            <template slot-scope="{ row }">
              {{
                selectDictLabel(dict.type.car_business_type, row.businessType)
              }}
            </template>
          </el-table-column>
          <el-table-column align="center" label="客户名称" width="120" prop="customerName"/>

          <el-table-column align="center" label="预计开始时间" width="140" prop="expectStartTime"/>
          <el-table-column align="center" label="预计结束时间" width="140" prop="expectEndTime"/>
          <el-table-column align="center" label="实际际开始时间" width="140" prop="actualStartTime"/>

          <el-table-column align="center" label="实际结束时间" width="140" prop="actualEndTime"/>
        </template>
      </table-page>
    </div>
  </div>
</template>

<script>
import {getDataList, delReplaceTyre} from "@/api/zcwh/ghltApi.js";

import {getToken} from "@/utils/auth";

import LinkageSelect from "../../components/linkageSelect";
import CitySelect from "../../components/citySelect.vue";
import SearchContent from "@/components/SearchContent/index.vue";

export default {
  name: "ghltList",

  dicts: ["car_business_type"],
  components: {
    SearchContent,
    LinkageSelect,
    CitySelect,
  },
  computed: {},
  data() {
    return {
      linkageList: [],
      citySelection: [],
      // 遮罩层
      loading: false,

      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: false,

      queryParams: {
        pageNum: 1,
        pageSize: 10,
        searchName: "",
        belongCityId: "",
        businessType: "",
        brandId: "",
        seriesId: "",
        modelId: "",
        customerName: "",
        maintenanceShop: "",
      },

      total: 0,
      dataList: [],
      createTime: [],
      time: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 导出按钮操作 */
    handleExport() {
      this.download(
          "/car/carReplaceTyre/export",
          {
            ...this.queryParams,
          },
          `更换轮胎管理列表_${new Date().getTime()}.xlsx`
      );
    },
    citySelectionChange(val) {
      if (val.length > 0) {
        const nodes = Array.from(val, (item) => ({
          value: item.value,
          label: item.label,
          pv: item.parent.value,
          pl: item.parent.label,
        }));
        this.queryParams.belongCityId = nodes[0].value;
        this.citySelection = [nodes[0].pv, nodes[0].value];
      } else {
        this.citySelection = val;

        this.queryParams.belongCityId = "";
      }
    },

    linkageChange(val) {
      this.linkageList = val;
      if (val) {
        this.queryParams.brandId = val[0] ? val[0].id : "";
        this.queryParams.seriesId = val[1] ? val[1].id : "";
        this.queryParams.modelId = val[2] ? val[2].id : "";
      } else {
        this.queryParams.brandId = "";
        this.queryParams.seriesId = "";
        this.queryParams.modelId = "";
      }
      this.$forceUpdate();
    },

    /** 查询测试单表列表 */
    getList() {
      this.loading = true;
      getDataList(this.queryParams).then((res) => {
        if (res.code == "200") {
          const {rows, total} = res;
          this.dataList = rows;
          this.total = total;
          this.loading = false;
        }
      }).catch(() => {
        this.loading = false;
      })
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.citySelection = [];
      this.linkageList = [];
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        searchName: "",
        belongCityId: "",
        businessType: "",
        brandId: "",
        seriesId: "",
        modelId: "",
        customerName: "",
        maintenanceShop: "",
        carNoVinNo:""
      }
      this.handleQuery();
    },

    viewOpen(row, type) {
      this.$router.push({
        path: "/clgl/ghltDetails",
        query: {
          id: row.carReplaceTyreId,
          // orderCode: row.orderCode,
        },
      });
    },
    del(row) {
      this.$confirm("是否删除这条信息?", "提示", {
        confirmButtonText: "删除",
        cancelButtonText: "取消",
        type: "warning",
      })
          .then(() => {
            delReplaceTyre(row.carReplaceTyreId).then((res) => {
              this.getList();
              this.$message({
                type: "success",
                message: res.msg,
              });
            });
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "已取消删除",
            });
          });
    },
  },
};
</script>

<style lang="scss" scoped>
.el-form {
  padding: 18px 20px;
  padding-bottom: 8px;
  background-color: #fff;
  border-radius: 8px;
  margin-bottom: 16px;

  ::v-deep .el-form-item {
    margin-bottom: 10px;
  }

  ::v-deep .el-form-item__label {
    font-size: 14px;
    font-family: 400;
  }
}
</style>
